package com.liuyi.producer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ProductConsumer {
	
    private Store<Porduct> mStore;
    private ExecutorService mWorkThread = Executors.newFixedThreadPool(1);

    public ProductConsumer bindStore(Store<Porduct> store) {
        this.mStore = store;
        return this;
    }

    public void consume() {
        mWorkThread.submit(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        Thread.currentThread().interrupt();
                    }
                    Porduct apple = mStore.take();
                    System.out.println("apple:" + apple.getName() + "消费了");
                }
            }
        });

    }
}
